from HttpTestcase.filters.testsuite_set_testsuite import suite_set_suiteFilters
from HttpTestcase.serializers import Testsuite2TestsuiteSerializer
from utils.mixins import *
from rest_framework.viewsets import GenericViewSet
from apps.HttpTestcase.models.testsuiteset2testsuite import TestsuiteSet2Testsuite


class TestSuiteSet2testsuiteViewSet(CreateModelMixin, ListModelMixin, GenericViewSet):
    queryset = TestsuiteSet2Testsuite.objects.filter(is_delete=False)
    serializer_class = Testsuite2TestsuiteSerializer
    filter_class = suite_set_suiteFilters


    def create(self, request, *args, **kwargs):
        data = request.data
        testsuite_set_id = data.get('testsuite_set_id')
        testsuite_list = data.get('data')
        TestsuiteSet2Testsuite.objects.filter(testsuite_set_id=testsuite_set_id).delete()
        # for item in testsuite_list:
        #     TestsuiteSet2Testsuite(**item)
        testsuite_set2testcase = [TestsuiteSet2Testsuite(**item) for item in testsuite_list]
        res = TestsuiteSet2Testsuite.objects.bulk_create(testsuite_set2testcase)
        return SuccessResponse(msg='创建成功！')
